import { baseUrl } from '@/config'
import { toast, showLoading, hideLoading } from '@/utils/utils'
import store from '@/store'
import JSONbig from 'json-bigint'

export function uploadFile(data = {}) {
  showLoading()
  return new Promise(resolve => {
    uni.uploadFile({
      url: baseUrl + 'sys/attachFiles/uploadAttachs',
      filePath: data.url,
      name: 'file',
      header: {
        Authorization: 'Bearer ' + store.state.token,
      },
      success: res => {
        hideLoading()
        res.data = JSONbig.parse(res.data)
        const data = res.data
        if (data.code === 200) {
          resolve(data.data)
        } else {
          toast(data.msg)
        }
      }
    })
  })
}